<?php

/**
 * This is the model class for table "{{module_2_chapters}}".
 *
 * The followings are the available columns in table '{{module_2_chapters}}':
 * @property integer $chapterId
 * @property string $chapterName
 * @property string $originalChapterName
 * @property integer $chapterSort
 * @property integer $isFirst
 * @property integer $isEnd
 * @property string $url
 * @property string $metaKeywords
 * @property string $metaDescription
 * @property string $prevUrl
 * @property string $nextUrl
 * @property integer $isShow
 * @property string $chapterNum
 */
class Chapter extends CActiveRecord
{
	public static $_tableName;
	public static $_bookId;
	
	public static function setTableId($bookId)
	{
		self::$_bookId = $bookId;
		self::$_tableName = '{{module_'.$bookId.'_chapters}}';
	}
	
	public function tableName()
	{
		return self::$_tableName;
	}
	
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Chapter the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}


	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('chapterName, originalChapterName, url, chapterSort', 'required'),
			array('chapterSort, isFirst, isEnd, isShow, sectionShow, isAddLock, isTypeLock, isUpdateLock, isSortLock, isTranslateLock', 'numerical', 'integerOnly'=>true),
			array('chapterName, originalChapterName, url, metaKeywords, prevUrl, nextUrl, chapterNum', 'length', 'max'=>255),
			array('metaDescription', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('chapterId, chapterName, originalChapterName, chapterSort, isFirst, isEnd, url, metaKeywords, metaDescription, prevUrl, nextUrl, isShow, chapterNum', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'chapterId' => '章节Id',
			'chapterName' => '中文名称',
			'originalChapterName' => '英文',
			'chapterSort' => '排序',
			'isFirst' => '首章',
			'isEnd' => '尾章',
			'url' => '标识',
			'metaKeywords' => '关键词',
			'metaDescription' => '描述',
			'prevUrl' => '上一章标识',
			'nextUrl' => '下一章标识',
			'isShow' => '显示章节',
			'chapterNum' => 'Chapter Num',
			'sectionShow' =>'显示段落',
			'isAddLock'=>'段落添加锁定',
			'isTypeLock'=>'段落类型修改锁定',
			'isSortLock'=>'段落排序锁定',
			'isUpdateLock'=>'段落修改锁定',
			'isTranslateLock'=>'段落翻译锁定'
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('chapterId',$this->chapterId);
		$criteria->compare('chapterName',$this->chapterName,true);
		$criteria->compare('originalChapterName',$this->originalChapterName,true);
		$criteria->compare('chapterSort',$this->chapterSort);
		$criteria->compare('isFirst',$this->isFirst);
		$criteria->compare('isEnd',$this->isEnd);
		$criteria->compare('url',$this->url,true);
		$criteria->compare('metaKeywords',$this->metaKeywords,true);
		$criteria->compare('metaDescription',$this->metaDescription,true);
		$criteria->compare('prevUrl',$this->prevUrl,true);
		$criteria->compare('nextUrl',$this->nextUrl,true);
		$criteria->compare('isShow',$this->isShow);
		$criteria->compare('chapterNum',$this->chapterNum,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}